<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" size="medium" class="ry_form">
      
        <el-form-item label="节目名称" prop="musicName">
          <el-input
            v-model="queryParams.musicName"
            placeholder="请输入节目名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
       
        <el-form-item class="flex_one tr">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
  
          >新增</el-button>
        </el-col>
      </el-row>
  
      <el-table v-loading="loading" :data="actorMangeList" >
        <!-- <el-table-column label="演员头像" align="center" prop="pic">
          <template slot-scope="{ row }">
            <el-image v-if="row.headImgurl" :src="row.headImgurl" :preview-src-list="[row.headImgurl]" class="small-img circle-img"/>
          </template>
        </el-table-column> -->
        <el-table-column label="节目名称" min-width="200" align="center" prop="musicName">
          <template slot-scope="{ row }">
            <div>{{row.musicName}}</div>
            
          </template>
        </el-table-column>
        <el-table-column label="演员" min-width="200" align="center" prop="actorName">
          <template slot-scope="{ row }">
            <div>{{row.actorName}}</div>
            
          </template>
        </el-table-column>
       
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >修改</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </template>
    <script>
  import {listplanitem,delplanitem} from "@/api/program/program";
  export default {
    dicts: [],
    data() {
      return {
            // 显示搜索条件
        showSearch: true,
        open: false,
        loading: false,
        actorMangeList: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          musicName:'',
          planId:''
        },
        goodId:'',
        total: 0,
      };
    },
    watch: {
    // 监听路由对象本身
    '$route'(to, from) {
      // 检查参数的变化
      console.log('9999')
      if (to.query.id!== from.query.id) {
        // 参数发生变化时的处理逻辑
        if(to.query.id){
          this.queryParams.planId=to.query.id
          this.goodId=to.query.goodId
          this.getList(to.query.id);
        }else{
          this.goodId=to.query.goodId
          this.actorMangeList=[]
        }
       
      }
    }
  },
    created() {
      const { id,goodId} = this.$route.query;
      this.goodId=goodId
      if (id) {
        this.queryParams.planId=id
        this.getList(id);
      }
    },
    methods: {
       /** 重置按钮操作 */
       resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      getList() {
          this.loading = true;
        const {pageNum, pageSize} = this.queryParams;
        const query = {...this.queryParams, pageNum: undefined, pageSize: undefined};
        const pageReq = {page: pageNum - 1, size: pageSize};
        listplanitem(query, pageReq).then(response => {
          const { content, totalElements } = response
          this.actorMangeList = content;
          this.total = totalElements;
          this.loading = false;
        });
      },
       /** 新增按钮操作 */
       handleAdd() {
       this.$router.push({ path: '/performManagement/AddPrigramMusic', query: { planId:this.queryParams.planId,goodId:this.goodId } });
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
       this.$router.push({ path: '/performManagement/AddPrigramMusic', query: { id: row.id,planId:this.queryParams.planId,goodId:this.goodId} });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除信息为"' + row.name + '"的数据项？').then(function() {
          return delplanitem(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
    },
  };
  </script>
    